package com.htzz.collection.core.mongo;

import com.htzz.collection.core.ActionTemplate;
import com.mongodb.MongoClient;

import org.bson.Document;

import java.util.List;
import java.util.Map;


public class MongoTemplate implements ActionTemplate {

    private MongoClient client;

    private String dataBaseName;

    public MongoTemplate(MongoClient client, String dataBaseName) {
        this.client = client;
        this.dataBaseName = dataBaseName;
    }

    @Override
    public boolean insert(String collectionName, Map<String,Object> json){
        if(json != null && !json.isEmpty()){
            client.getDatabase(dataBaseName).getCollection(collectionName).insertOne(new Document(json));
            return true;
        }
        return false;

    }

	@Override
	public boolean insertMany(String collectionName,List<Document> jsons) {
		if(jsons.size()>0){
			client.getDatabase(dataBaseName).getCollection(collectionName).insertMany(jsons);
			return true;
		}
		return false;
	}


}
